package com.ys.nms.module.business.controller.admin.vlans;

import com.baomidou.dynamic.datasource.annotation.Slave;
import com.fhs.core.trans.anno.TransMethodResult;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.ys.nms.framework.common.pojo.PageParam;
import com.ys.nms.framework.common.pojo.PageResult;
import com.ys.nms.framework.common.pojo.CommonResult;
import com.ys.nms.framework.common.util.object.BeanUtils;
import static com.ys.nms.framework.common.pojo.CommonResult.success;

import com.ys.nms.framework.excel.core.util.ExcelUtils;

import com.ys.nms.framework.apilog.core.annotation.ApiAccessLog;
import static com.ys.nms.framework.apilog.core.enums.OperateTypeEnum.*;

import com.ys.nms.module.business.controller.admin.vlans.vo.*;
import com.ys.nms.module.business.dal.dataobject.vlans.VlansDO;
import com.ys.nms.module.business.service.vlans.VlansService;

@Tag(name = "管理后台 - vlans")
@RestController
@RequestMapping("/business/vlans")
@Validated
public class VlansController {

    @Resource
    private VlansService vlansService;

    @PostMapping("/create")
    @Operation(summary = "创建vlans")
    public CommonResult<Integer> createVlans(@Valid @RequestBody VlansSaveReqVO createReqVO) {
        return success(vlansService.createVlans(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新vlans")
    public CommonResult<Boolean> updateVlans(@Valid @RequestBody VlansSaveReqVO updateReqVO) {
        vlansService.updateVlans(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除vlans")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteVlans(@RequestParam("id") Integer id) {
        vlansService.deleteVlans(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除vlans")
    public CommonResult<Boolean> deleteVlansList(@RequestParam("ids") List<Integer> ids) {
        vlansService.deleteVlansListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得vlans")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<VlansRespVO> getVlans(@RequestParam("id") Integer id) {
        VlansDO vlans = vlansService.getVlans(id);
        return success(BeanUtils.toBean(vlans, VlansRespVO.class));
    }

    @Slave
    @TransMethodResult
    @GetMapping("/page")
    @Operation(summary = "获得vlans分页")
    public CommonResult<PageResult<VlansRespVO>> getVlansPage(@Valid VlansPageReqVO pageReqVO) {
        PageResult<VlansDO> pageResult = vlansService.getVlansPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, VlansRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出vlans Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportVlansExcel(@Valid VlansPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<VlansDO> list = vlansService.getVlansPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "vlans.xls", "数据", VlansRespVO.class,
                        BeanUtils.toBean(list, VlansRespVO.class));
    }

}